//首页控制器
app.controller('userLoginController',function($scope,$location,$controller,userLoginService,userOrderService){
	$controller("commonController",{$scope:$scope});

	//查询所有订单
	$scope.findAll=function (status) {
		userOrderService.findAll(status).success(
			function (response) {
				$scope.entity=response;
				//得到总数据量
				$scope.totalNum=$scope.entity.length;
				//总页数,向上取整
				$scope.totalPage=Math.ceil($scope.totalNum/$scope.pageSize);
				$scope.pageData=$scope.entity.slice(0,$scope.pageSize);
			}
		);
	}
	$scope.orderStatus=["未支付","未发货","","已发货","交易成功","交易关闭","申请退款中","退款成功"];
	//查询订单详情
	$scope.findOrderItem=function () {
		var orderId=$location.search()["orderId"];
		userOrderService.findOrderItem(orderId).success(
			function (response) {
				$scope.map=response;
			}
		);
	}

	//修改订单状态
	$scope.updateStatus=function (id,status) {
		userOrderService.updateStatus(id,status).success(
			function (response) {
				alert(response.message);
			}
		)
	}
	//提交退款
	$scope.submitRefundRequest=function (id) {
		let confirm1 = confirm('是否申请退款');
		if (confirm1){
			userOrderService.submitRefundRequest(id).success(
				function (response) {
					alert(response.object);
				}
			)
		}
	}

	//-----分页功能start----------
	//页码
	$scope.pageNum=1;
	//当前页
	$scope.currentPage=1;
	//页大小
	$scope.pageSize=4;
	$scope.getPageData=function (num) {
			//每页数据
			$scope.pageData=[];
			$scope.currentPage=$scope.currentPage+num;
			//索引位置
			$scope.start=($scope.currentPage-1)*$scope.pageSize;
			$scope.end=$scope.start+$scope.pageSize;
			$scope.pageData=$scope.pageData=$scope.entity.slice($scope.start,$scope.end);
	}
	//---------分页功能end----------

	//----------------修改密码和用户名start-------
	$scope.passwordEntity={};
	$scope.updatePassword=function () {
		if ($scope.passwordEntity.password != $scope.surePassword){
			alert("两次输入密码不一致")
		}
		userLoginService.updatePassword($scope.passwordEntity).success(
			function (response) {
				//成功
				if (200==response.code){
					location.href="logout/cas";
				}else{
					alert(response.message);
				}
			}
		);
	}
	//-----------------修改密码和用户名 end----------

	$scope.seller={};
	//忘记密码
	$scope.forgetPassword=function(username){
		//更新
		userLoginService.forgetPassword($scope.seller).success(
			function(response){
				if (200==response.code){
					alert(response.object);
					location.href="http://localhost:8087/"
				}else{
					alert(response.object);
				}
			}
		);
	}
	//发送验证码
	$scope.sendCode=function(){
		if($scope.seller.email==null || $scope.seller.email==""){
			alert("请填写邮箱");
			return ;
		}
		userLoginService.sendCode($scope.seller.email).success(
			function(response){
				alert(response.object);
			}
		);
	}

});